<?php
namespace app\admin\controller;
use think\Request;

class Message extends Base
{
	public $req;
	protected $MessageModel;

	public function __construct() {
		parent::__construct();
		$this->req = Request::instance();
		$this->MessageModel = model('MessageModel');
	}

	/**
	 * 留言列表
	 */
	public function meslist() {
		if ($this->req->isPost()) {
			$data = $this->req->post();

			$list = $this->MessageModel->getAllByPage(
				($data['page']-1)*$data['limit'],
				$data['limit']
			);
			$count = $this->MessageModel->count();

			return layuiJson(0, '', $count, $list);

		} else {
			return $this->fetch();
		}
	}

	/**
	 * 删除留言
	 */
	public function editStatus() {
		$id = input('post.id');
		$res = $this->MessageModel->save(['deleted_at' => date('Y-m-d H:i:s')],[ 'id'=>$id ]);
		if ($res == 1) {
			return show(0, '删除成功');
		}
		return show(1, '删除失败');
	}
}
